<template>
	<view class="date-filter-bar">
		<view class="range-select" @click="calendarShow = true" v-if="isRecord === true">
			<view class="select-text">{{ selectedTimeRange }}</view>
			<u-icon name="calendar"></u-icon>
		</view>

		<view class="type-select" @click="slectShow = true" v-else>
			<view class="select-text">{{ selectedType }}</view>
			<u-icon name="arrow-down"></u-icon>
		</view>

		<view v-for="item in dateFilters" :key="item.value"
			:class="['date-btn', activeDate === item.value ? 'active' : '']"
			@click="$emit('updateActiveDate', item.value)">
			{{ item.label }}
		</view>

		<!-- 检查类型筛选 -->
		<u-select v-model="slectShow" :list="typeList" @confirm="confirmType"></u-select>

		<!-- 时间范围筛选 -->
		<u-calendar v-model="calendarShow" @change="confirmTimeRange" :mode="mode"></u-calendar>
	</view>
</template>

<script>
	export default {
		props: {
			dateFilters: {
				type: Array,
				default: () => [{
						label: '一月内',
						value: '1m'
					},
					{
						label: '半年内',
						value: '6m'
					},
					{
						label: '一年内',
						value: '1y'
					},
					{
						label: '全部',
						value: 'all'
					},
				]
			},
			activeDate: {
				type: String,
				default: '1m'
			},
			typeList: {
				type: Array,
				default: () => [{
						label: '全部',
						value: 'all'
					},
					{
						label: '检验检查',
						value: 'inspection'
					},
					{
						label: '病理检查',
						value: 'pathology'
					},
					{
						label: '放射检查',
						value: 'radiation'
					},
					{
						label: '超声检查',
						value: 'ultrasonic'
					},
				]
			},
			selectedType: {
				type: String,
				default: '全部'
			},
			selectedTimeRange: {
				type: String,
				default: '请选择时间范围'
			},
			isRecord: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				slectShow: false,
				calendarShow: false,
				mode: 'range',

			}
		},
		methods: {
			confirmType(type) {
				this.$emit('type-selected', {
					label: type[0].label,
					value: type[0].value
				});
			},
			confirmTimeRange(timeRange) {
				this.$emit('time-range-selected', {
					startDate: timeRange.startDate,
					endDate: timeRange.endDate
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.date-filter-bar {
		display: flex;
		justify-content: space-between;
		margin: 24rpx 0 0;
	}

	.range-select {
		width: 260rpx;
		display: flex;
		justify-content: space-around;
		background: #f2f6fa;
		border-radius: 8rpx;
		text-align: center;
		padding: 14rpx 16rpx;
		margin-right: 20rpx;
		white-space: nowrap;
	}

	.type-select {
		width: 190rpx;
		display: flex;
		justify-content: space-around;
		background: #f2f6fa;
		border-radius: 8rpx;
		text-align: center;
		padding: 14rpx 20rpx;
		margin-right: 20rpx;
	}

	.select-text {
		font-size: 28rpx;
		margin-right: 10rpx;
		color: #666;
	}

	.date-btn {
		flex: 1;
		text-align: center;
		padding: 14rpx 0;
		font-size: 26rpx;
		color: #666;
		background: #f2f6fa;
		border-radius: 8rpx;
		margin-right: 12rpx;

		&:last-child {
			margin-right: 0;
		}

		&.active {
			background: #1ec6e6;
			color: #fff;
			font-weight: bold;
		}
	}
</style>